package com.example.aircraftticketingsystemserver.service.impl;

import com.example.aircraftticketingsystemserver.entity.Passenger;
import com.example.aircraftticketingsystemserver.entity.UserPassenger;
import com.example.aircraftticketingsystemserver.mapper.UserPassengerMapper;
import com.example.aircraftticketingsystemserver.service.IUserPassengerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.aircraftticketingsystemserver.utils.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lxz
 * @since 2024-08-19
 */
@Service
public class UserPassengerServiceImpl extends ServiceImpl<UserPassengerMapper, UserPassenger> implements IUserPassengerService {
    @Resource
    private UserPassengerMapper userPassengerMapper;
    @Override
    public Page getPassengersByUserId(Integer pageNo,
                                      Integer pageSize,
                                      Integer userId,
                                      String passengerNumber,
                                      String passengerName,
                                      String passengerPhone) {
        Page page=new Page();
        PageHelper.startPage(pageNo,pageSize);
        List<Passenger> passengers=userPassengerMapper.findPassengersByUserId(userId,passengerNumber,passengerName,passengerPhone);
        PageInfo<Passenger> info=new PageInfo<>(passengers);
        page.setPage(info.getList());
        page.setPageNo(info.getPageNum());
        page.setPageSize(info.getPageSize());
        page.setHasNext(info.isHasNextPage());
        page.setHasPre(info.isHasPreviousPage());
        page.setTotal(info.getTotal());
        page.setPageCount(info.getPages());
        return page;
    }

    @Override
    public List<Passenger> getPassengerList(Integer userId) {
        List<Passenger> passengerList = userPassengerMapper.getPassengerList(userId);
        return passengerList;
    }

    @Override
    public List<Passenger> getPassengerByParams(Integer userId, String passengerNumber, String passengerName, String passengerPhone) {
        List<Passenger> passengerList = userPassengerMapper.findPassengersByUserId(userId, passengerNumber, passengerName, passengerPhone);
        return passengerList;


    }


}
